<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />

<style type="text/css">
</style>

</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">
					<%@ include file="fncGroupCompanyAccountInclude.jsp"%>

			<c:if test="${operate == 'openAccount'}">
						<div class="caption">
							<span class="title">开户申请信息</span>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请人</div>
							<div class="field">
								<input id="applUsrNm" name="applUsrNm" type="text" class="ui-textbox"
									ligerui="width: <%=width%>" disabled="disabled"
									value="${fncGroupCompanyAccountVO.applUsrNm}" />
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请日期</div>
							<div class="field">
								<input id="applDate" name="applDate" type="text" disabled="disabled"
									ligerui="width: <%=width%>" class="ui-datepicker"
									value="${fncGroupCompanyAccountVO.applDate}" />
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请人所属部门</div>
							<div class="field">
								<input id="applOrg" name="applOrg" type="text" class="ui-textbox"
									ligerui="width: <%=width%>" disabled="disabled"
									value="${fncGroupCompanyAccountVO.applOrg}" />
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请人电话</div>
							<div class="field">
								<input id="applPhone" name="applPhone" type="text" class="ui-textbox"
									ligerui="width: <%=width%>" validate="{required:true,mobile:true}"
									value="${fncGroupCompanyAccountVO.applPhone}" />
							</div>
						</div>
						<div class="fieldBox col_100">
							<div class="label">申请原因</div>
							<div class="field">
								<input id="applReason" name="applReason" type="text" class="ui-textbox"
									ligerui="width: <%=width%>" validate="{required:true}"
									value="${fncGroupCompanyAccountVO.applReason}" />
							</div>
						</div>
						
						<!-- 附件上传 -->
						<div class="fieldBox col_100" >
							<div class="label">申请原因附件</div>
							<div class="field">
								<div id="fileUpload2" class="upfileBoxs"></div>
								<span class="sq-button sq-button-hasicon" id="btnUpload2" onclick="ajaxFileUploadImg('uploads2',1)">
									<i class="sqBtnIco_9"></i>上传
								</span>
									
							</div>
						</div>
						
						<!-- 附件显示 -->
						<div class="fieldBox col_100">
							<div style="width: 98%; margin-left: 1%;">
				            
								<div id="ligergrid_file1" class="sq-grid"></div>
							</div>
						</div>
					
						</c:if>
						
						
						
					<c:if test="${operate == 'closeAccount' }">
						<div class="caption">
							<span class="title">销户申请信息</span>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请人</div>
							<div class="field">
								<input id="applCancelUsrNm" name="applCancelUsrNm" type="text" class="ui-textbox"
									ligerui="width: <%=width%>" disabled="disabled"
									value="${fncGroupCompanyAccountVO.applCancelUsrNm}" />
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请日期</div>
							<div class="field">
								<input id="applCancelDate" name="applCancelDate" type="text" disabled="disabled"
									ligerui="width: <%=width%>" class="ui-datepicker"
									value="${fncGroupCompanyAccountVO.applCancelDate}" />
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请人所属部门</div>
							<div class="field">
								<input id="applCancelOrg" name="applCancelOrg" type="text" class="ui-textbox"
									ligerui="width: <%=width%>" disabled="disabled"
									value="${fncGroupCompanyAccountVO.applCancelOrg}" />
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">申请人电话</div>
							<div class="field">
								<input id="applCancelPhone" name="applCancelPhone" type="text" class="ui-textbox"
									ligerui="width: <%=width%>" validate="{required:true,mobile:true}"
									value="${fncGroupCompanyAccountVO.applCancelPhone}" />
							</div>
						</div>
						<div class="fieldBox col_100">
							<div class="label">申请原因</div>
							<div class="field">
								<input id="applCancelReason" name="applCancelReason" type="text" class="ui-textbox"
									ligerui="width: <%=width%>" validate="{required:true}"
									value="${fncGroupCompanyAccountVO.applCancelReason}" />
							</div>
						</div>
						
						<!-- 附件上传 -->
						<div class="fieldBox col_100" >
							<div class="label">申请原因附件</div>
							<div class="field">
							   
								 
								<div id="fileUpload2" class="upfileBoxs"></div>
								<span class="sq-button sq-button-hasicon" id="btnUpload2" onclick="ajaxFileUploadImg('uploads2',1)">
									<i class="sqBtnIco_9"></i>上传
								</span>
									
							</div>
						</div>
						<!-- 附件显示 -->
						<div class="fieldBox col_100">
							<div style="width: 98%; margin-left: 1%;">
				            
								<div id="ligergrid_file1" class="sq-grid"></div>
							</div>
						</div>
						
						</c:if>

				<div class="btnsBox">
					<c:if test="${operate == 'openAccount'}">
						<span id="saveBtn" class="sq-button sq-button-round"
							onclick="save('openAccount');">发起开户申请流程</span>
					</c:if>
					<c:if test="${operate == 'closeAccount'}">
						<span id="saveBtn" class="sq-button sq-button-round"
							onclick="save('closeAccount');">发起销户申请流程</span>
					</c:if>
				</div>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
	     
		$(function() {
			$("#ligerForm").ligerForm({
		        validate : true
		    });
			
			
			//设置省、市
            setRgnProvCdUpdataValue("${fncGroupCompanyAccountVO.bankProv}");
            setRgnCityCdUpdataValue("${fncGroupCompanyAccountVO.bankCity}");
            
         	//设置上半部分不可用
        	setTopDisabled();
        	loadFilesLiger("accountData", 2, "${fncGroupCompanyAccountVO.id}", "yes");
        	<c:if test="${operate == 'openAccount'}">
	        	//开户申请附件列表
	        	loadFilesLiger("openAccount", 1, "${fncGroupCompanyAccountVO.id}", "yes");
	        	loadFilesLiger("accountData", 2, "${fncGroupCompanyAccountVO.id}", "no");
        	</c:if>
        	<c:if test="${operate == 'closeAccount'}">
	        	//销户申请附件列表
	        	loadFilesLiger("closeAccount", 1, "${fncGroupCompanyAccountVO.id}", "yes");
	        	loadFilesLiger("accountData", 2, "${fncGroupCompanyAccountVO.id}", "no");
	    	</c:if>
	    });
		
		function setTopDisabled(){
			liger.get("groupCompanyId").setDisabled(true);
			liger.get("buOrgcd").setDisabled(true);
			liger.get("bank").setDisabled(true);
			liger.get("bankName").setDisabled(true);
			liger.get("bankAddress").setDisabled(true);
			liger.get("currency").setDisabled(true);
			liger.get("bankNature").setDisabled(true);
			liger.get("accountCloseDate").setDisabled(true);
			liger.get("bankUse").setDisabled(true);
			liger.get("rgnProvCd").setDisabled(true);
			liger.get("rgnCityCd").setDisabled(true);
			liger.get("isOnlineAccount").setDisabled(true);
			liger.get("isNetBank").setDisabled(true);
			liger.get("accountOpenDate").setDisabled(true);
			liger.get("bankAccount").setDisabled(true);
			liger.get("cstMgr").setDisabled(true);
			liger.get("corpName").setDisabled(true);//法人姓名
			liger.get("corpPhone").setDisabled(true);//法人预留电话
			liger.get("operName").setDisabled(true);//经办人
			liger.get("operPhone").setDisabled(true);//经办人预留电话
		}
		
		
		function save(operate){
			
			//验证
			var ligerForm = liger.get("ligerForm");
			if (!ligerForm.valid()) {
			    	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning",SQ_showButtons: true});
		            return ; 
		     }
			/*if($.trim($("#idCard").val()) == ""){
					$.ligerDialog.SQalert({content: "输入工号，点击'查找收件人'，查询出收件人（工号）和收件人（姓名）",SQ_type: "warning",SQ_showButtons: true});
					return ;
			} */ 
		   
		   
			//组织数据，提交后台
			var data = ligerForm.getData();
				
			data["id"] = "${fncGroupCompanyAccountVO.id}";
			data["bankProv"] = data.rgnProvCd;//开户地-省
			data["bankCity"] = data.rgnCityCd;//开户地-市
			
			data["applUsrId"] = "${fncGroupCompanyAccountVO.applUsrId}";
			data["applOrgCd"] = "${fncGroupCompanyAccountVO.applOrgCd}";
			
			data["applCancelUsrId"] = "${fncGroupCompanyAccountVO.applCancelUsrId}";
			data["applCancelOrgCd"] = "${fncGroupCompanyAccountVO.applCancelOrgCd}";
			
			console.log(data);
			//return;
			
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: '<%=path%>/account/fncGroupCompanyAccount/save.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : LogUtils.LOG_CMM_DATA_LOADING,
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						//保存文件
						saveFile(msg.info,operate);
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					wait_dialog.close();
					$.ligerDialog.SQalert({
						content : "网络错误，请稍后重试",
						SQ_type : "error"
					});
				}
			});
		}
		
		//发起流程
		function startFlow(operate){
			
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				url: '<%=path%>/account/fncGroupCompanyAccount/startFlow.do?id=${fncGroupCompanyAccountVO.id}&operate='+operate,
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : LogUtils.LOG_CMM_DATA_LOADING,
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						//alert(msg.info);
						top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
						Remove_navTab();//关闭当前页面
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					wait_dialog.close();
					$.ligerDialog.SQalert({
						content : "网络错误，请稍后重试",
						SQ_type : "error"
					});
				}
			});
		}
		
		//保存文件
		function saveFile(info,operate){
			var docArray = JSON.stringify(getUploadResultParams(1));
	        var url = "<%=path%>/rfcont/fncPrjContAudit/uploadAttchment.do";
        	if(null == docArray){
        		//无要上传的文件-直接结束
        		//top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
        		//发起流程
				startFlow(operate);
        	}else{
        		var pkId = "${fncGroupCompanyAccountVO.id}";
		        if(pkId){//主表ID不为空执行
			        //赋值附件
			        var data = {
						"docArray":docArray,
						"pkId": pkId,
						"flag": "${operate}"
					};
					//请求
			        AjaxUtils.ajaxPost(url, data, function(msg){
			        	if(msg.success == 1){
							 //top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
							 if(msg.data){
								 //清空上传文件缓存
								 clearUploadResultParams(2);
							 }
							 startFlow(operate);
							 //Remove_navTab();//关闭申请窗口
						 }else{
							 UIUtils.alertError(msg.info);
						 }
			        }, true);
		        }else{
		        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
		        }
        	}
		}
		//保存文件
		function saveFile2(pkId){
			var docArray = JSON.stringify(getUploadResultParams(2));
	        var url = "<%=path%>/rfcont/fncPrjContAudit/uploadAttchment.do";
        	if(null == docArray){
        		//无要上传的文件-直接结束
        		//top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
        	}else{
		        if(pkId){//ID不为空执行
			        //赋值附件
			        var data = {
						"docArray":docArray,
						"pkId": pkId,
						"flag": "accountData"
					};
					//请求
			        AjaxUtils.ajaxPost(url, data, function(msg){
			        	if(msg.success == 1){
							 //top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
							 if(msg.data){
								 clearUploadResultParams(2);
							 }
						 }else{
							 UIUtils.alertError(msg.info);
						 }
			        }, true);
		        }else{
		        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
		        }
        	}
		}
		//显示已上传但是未保存的文件列表
		function showFiles(data, index){
			var sysDate = $("#sysDate").val();
			var loginUsrNm = $("#loginUsrNm").val();
			var f_Grid = liger.get("ligergrid_file"+index);
			var uploadJOSN = data;
    		for (var i=0; i< uploadJOSN.length; i++){ 
        		//添加行-追加行
        		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index, id: i});
    		}
		}
	</script>
</body>
</html>